<!DOCTYPE html>
<html>
<head>
    <title>挂号--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>
 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
        let hosrId = window.location.href.split("?")[1].split("=")[1];
        $(function () {
            $('#backid').click(function () {
                window.location.href = "index.html";
            });
            $.ajax({
                url: "findByHosrId",
                data: {"hosrId": hosrId},
                type: "post",
                dataType: "json",
                success: function (resp) {
                    if (resp.flag) {
                        // console.info("-------------")
                        $("#xunhuan").empty();
                        // console.log(resp.data.hosregister);
                        // console.info("-------------")
                        let hosregister = resp.data.hosregister;
                        let dId = hosregister.doctor.dId;
                        // console.log(dId);
                        // console.log("hhh")
                        $.ajax({
                            url:"findByDoctorId",
                            data:{"dId":dId},
                            type:"post",
                            dataType:"json",
                            success:function (response){
                                console.log(response);
                                let doc = response.data.doctor;
                                if(response.flag){
                                    // console.log("aaa");
                                    // console.log(doc);
                                    let dName = doc.dName;
                                    // console.log(dName);
                                    let dKeshi = doc.dKeshi;
                                    // console.log(dKeshi);
                                    // console.log(dName);
                                    // console.info(hosregister)
                                    var hosrId = $("input[name='hosrId']").val(hosregister.hosrId);
                                    var hosrIdcar = $("input[name='hosrIdcar']").val(hosregister.hosrIdcar);
                                    var hosrMedical = $("input[name='hosrMedical']").val(hosregister.hosrMedical);
                                    var hosrRegprice = $("input[name='hosrRegprice']").val(hosregister.hosrRegprice);
                                    var hosrPhone = $("input[name='hosrPhone']").val(hosregister.hosrPhone);
                                    // var hosrSelfprice = $("input[name='hosrSelfprice']").val(selfprice(hosregister.hosrSelfprice));
                                    // var hosrSex = $("input[name='hosrSex']").val(sexfo(hosregister.hosrSex));
                                    var hosrAge = $("input[name='hosrAge']").val(hosregister.hosrAge);
                                    var hosrWork = $("input[name='hosrWork']").val(hosregister.hosrWork);
                                    // var hosrLookdoctor = $("input[name='hosrLookdoctor']").val(lookdoctor(hosregister.hosrLookdoctor));
                                    $("#dId").val(hosregister.dId);
                                    var hosrName = $("#hosrName").val(hosregister.hosrName);
                                    var hosrRemark = $("#hosrRemark").val(hosregister.hosrRemark);
                                    $("#dKeshi").append("<option value='"+dKeshi+"'>"+dKeshi+"</option>");
                                    $("#dName").append("<option value='"+dName+"'>"+dName+"</option>");
                                }
                            }
                        })
                    }
                }
            })
        });
      //  init(hosrId);

        // F 女 , M 男 (female 女,male 男)
        function getSexByIdNO(IdNO) {
            if (IdNO.length == 18) {
                return IdNO.charAt(16) % 2 == 0 ? "F" : "M";
            } else if (IdNO.length == 15) {
                return IdNO.charAt(14) % 2 == 0 ? "F" : "M";
            } else {
                return "";
            }
        }
        //获取年龄
        function getAge(userCard){
            //获取年龄
            var yearBirth = userCard.substring(6,10);
            var monthBirth = userCard.substring(10,12);
            var dayBirth = userCard.substring(12,14);
            //获取当前年月日并计算年龄
            var myDate = new Date();
            var monthNow = myDate.getMonth() + 1;
            var dayNow = myDate.getDay();
            var age = myDate.getFullYear() - yearBirth;
            if(monthNow < monthBirth || (monthNow == monthBirth && dayNow < dayBirth)){
                age--;
            }
            // let nowYear = new Date(),getFullYear;
            // let my =  getBirthdayByIdNO(userCard).split("-")[0]
            return age;
        }
        function changeIdCar() {
            let hosrIdcar = $("hosrIdcar").val();
            //身份证号验证
            if (hosrIdcar == null || hosrIdcar == '') {
                alert("名字为空");
                return;
            } else {
                var myreg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                if (!myreg.test(hosrIdcar)) {
                    alert("身份证格式不正确")
                        $("hosrIdcar").val("");
                        return;
                    }
                }
            //获取性别
            let sexBox = $("input[name='hosrSex']");
            if (sexBox != '') {
                if (getSexByIdNO(hosrIdcar) == 'F') {
                    sexBox.prop({"value": "1"})
                } else {
                    sexBox.prop({"value": "0"})
                }
            } else {
                console.log("获取性别失败")
            }
            //获取年龄
            $("hosrIdcar").val(getAge(hosrIdcar));
        }

        function mybaocun() {
            var hosrId = $("input[name='hosrId']").val();
            var hosrIdcar = $("input[name='hosrIdcar']").val();
            var hosrMedical = $("input[name='hosrMedical']").val();
            var hosrRegprice = $("input[name='hosrRegprice']").val();
            var hosrPhone = $("input[name='hosrPhone']").val();
            var hosrSelfprice = $("input[name='hosrSelfprice']:checked").val();
            var hosrSex = $("input[name='hosrSex']:checked").val();
            var hosrAge = $("input[name='hosrAge']").val();
            var hosrWork = $("input[name='hosrWork']").val();
            var hosrLookdoctor = $("input[name='hosrLookdoctor']:checked").val();
            var hosrName = $("#hosrName").val();
            var hosrRemark = $("#hosrRemark").val();

            console.log(hosrLookdoctor)
            //发送ajax请求
            $.ajax({
                url: "updateRegistration",
                data: {
                    'hosrId': hosrId,
                    'hosrName': hosrName,
                    'hosrIdcar': hosrIdcar,
                    'hosrMedical': hosrMedical,
                    'hosrRegprice': hosrRegprice,
                    'hosrPhone': hosrPhone,
                    'hosrSelfprice': hosrSelfprice,
                    'hosrSex': hosrSex,
                    'hosrAge': hosrAge,
                    'hosrWork': hosrWork,
                    'hosrLookdoctor': hosrLookdoctor,
                    'hosrRemark': hosrRemark
                },
                type: 'post',
                //contentType: "application/json;charset=UTF-8",
                dataType: 'json',
                success: function (resp) {
                    if (resp.code==200) {
                        alert("修改成功！");
                    }else {
                        alert("修改失败！");
                    }
                }
            })

            //数据验证
            if (hosrName == null || hosrName == '') {
                alert("名字为空");
                return;
            }
            //手机号验证
            if (hosrPhone == null || hosrPhone == '') {
                alert("手机号为空");
                return;
            } else {
                let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
                if (!myreg.test(hosrPhone)) {
                    alert("手机号格式不正确!");
                    return;
                }
            }
            if (hosrWork == null || hosrWork == '') {
                alert("职业为空");
                return;
            }

            if (hosrMedical == null || hosrMedical == '') {
                alert("社保号为空");
                return;
            } else {
                var myreg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                if (!myreg.test(hosrIdcar)) {
                    alert("社保号格式不正确")
                    $("input[name='hosrMedical']").val("");
                    return;
                }
            }

        };
        function sexfo(sex){
            if (sex == 1){
                return "女";
            }else {
                return "男";
            }
        }

        function selfprice(selfprice){
            if (selfprice==0){
                return "自费";
            }else {
                return "免费";
            }
        }

        function lookdoctor(lookdoctor){
            if (lookdoctor == 0){
                return "初诊";
            }else {
                return "复诊";
            }
        }
        function stringtocode(name){//字符转换为编码用“,”隔开每个字符
            var result=String();
            if(name==''||name==undefined) return name;
            for(var i=0;i<name.length;i++){
                result+=name.charCodeAt(i)+",";
            }
            result=result.substring(0,result.length-1);
            return result;
        }
        function codetostring(cod){//编码转换成字符，编码之间用,分开
            var result=String(),a=new Array();
            a=cod.split(",");
            for(var i=0;i<a.length;i++)
                result+=String.fromCharCode(parseInt(a[i]));
            return result;
        }
    </script>

</head>
<body>
<form action="../../index.html" method="post" class="definewidth m20">
<table  class="table table-bordered table-hover definewidth m10">
    <tr>
        <input type="hidden" name="hosrId"/>
        <td width="10%" class="tableleft">姓名</td>
        <td><input id="hosrName" type="text" name="hosrName" value="陆小凤"/></td>
    </tr>

    <tr>
        <td width="10%" class="tableleft">身份证号</td>
        <td><input id="hosrIdcar" type="text" name="hosrIdcar" value="21324324324"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">社保号</td>
        <td><input id="hosrMedical" type="text" name="hosrMedical" value="453253453"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">挂号费</td>
        <td><input id="hosrRegprice" type="text" name="hosrRegprice" value="5"/>元</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">联系电话</td>
        <td><input id="hosrPhone" type="text" name="hosrPhone" value="13543235678"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">是否自费</td>
        <td><input id="hosrSelfprice" type="radio" name="hosrSelfprice" value="0" checked/>否&nbsp;&nbsp;&nbsp;
            <input id="hosrSelfprice1" type="radio" name="hosrSelfprice" value="1"/>是</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">性别</td>
        <td><input  type="radio" name="hosrSex" value="0" checked />男&nbsp;&nbsp;&nbsp;
            <input  type="radio" name="hosrSex" value="1"/>女</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">年龄</td>
        <td><input id="hosrAge" type="text" name="hosrAge" value="33"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">职业</td>
        <td><input id="hosrWork" type="text" name="hosrWork" value="狗仔队"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">初复诊</td>
        <td><input  type="radio" name="hosrLookdoctor" value="0" checked/>初诊&nbsp;&nbsp;&nbsp;
            <input  type="radio" name="hosrLookdoctor" value="1"/>复诊</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">所挂科室</td>
        <td><select id="dKeshi" name="dKeshi">
<!--            <option value="急诊科">急诊科</option>-->
<!--            <option value="骨科">骨科</option>-->
<!--            <option value="血液科">血液科</option>-->
        </select></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">指定医生</td>
        <td><select id="dName" name="dName" >
<!--            <option>程俊</option>-->
<!--            <option>欧阳雨露</option>-->
<!--            <option>王博</option>-->
        </select></td>
    </tr>
	<tr>
        <td width="10%" class="tableleft">备注</td>
        <td><textarea id="hosrRemark" name="hosrRemark">此人疑拟有精神病</textarea></td>
	</tr>
    <tr>
        <td colspan="2">
			<center>
				<button class="btn btn-primary" type="button" onclick="mybaocun()" value="保存">保存</button> &nbsp;&nbsp;
                <button type="button" class="btn btn-success" name="backid" id="backid" value="返回列表">返回列表</button>
			</center>
		</td>
    </tr>
</table>
</form>
</body>
</html>